package theeg.DependencyAnalysis.Core.Internal;

import theeg.DependencyAnalysis.Core.DataModel.*;

import java.util.Map;
import java.util.Set;

public class DependencyModelConverter {

    private DependencyModelConverter() {
    }

    public static <T extends Descriptor> Map<T, Set<DependencyDescriptor>> getDependencyStructureIn(DependencyModel model, Class<T> descriptorClass)
    {
        if (descriptorClass == MemberDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerMember();
        }
        if (descriptorClass == TypeDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerType();
        }
        if (descriptorClass == SubmoduleDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerSubmodule();
        }
        if (descriptorClass == ModuleDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerModule();
        }
        throw new IllegalArgumentException();
    }

    public static <T extends Descriptor> Map<T, Set<DependencyDescriptor>> getDependencyStructureOut(DependencyModel model, Class<T> descriptorClass)
    {
        if (descriptorClass == MemberDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerMemberOut();
        }
        if (descriptorClass == TypeDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerTypeOut();
        }
        if (descriptorClass == SubmoduleDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerSubmoduleOut();
        }
        if (descriptorClass == ModuleDescriptor.class) {
            return (Map<T, Set<DependencyDescriptor>>)model.getDependenciesPerModuleOut();
        }
        throw new IllegalArgumentException();
    }
}
